package com.tuanzi.loan.web.bean.receipt.statistics;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.constants.DictionaryCode;
import com.tuanzi.loan.business.service.receipt.statistics.ReceiptOrderStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.tuanzi.loan.business.entity.receipt.product.ReceiptProductInfo;
import com.tuanzi.loan.business.service.receipt.product.ReceiptProductInfoService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.receipt.statistics.ReceiptOrderStatisticsRequest;
import com.tuanzi.loan.vo.response.receipt.statistics.ReceiptOrderStatisticsResponse;
import com.tuanzi.loan.web.configuration.JSFListingBean;
import com.tuanzi.loan.web.lazy.receipt.statistics.ReceiptOrderStatisticsLazyDataModel;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author Ray 2017/09/21
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class ReceiptOrderStatisticsBean extends JSFListingBean<ReceiptOrderStatisticsRequest, ReceiptOrderStatisticsResponse> {

	private static final long serialVersionUID = 30992312030673477L;

	@Autowired
	private ReceiptProductInfoService receiptProductInfoService;


	private List<ReceiptProductInfo> receiptProductInfos;

	@PostConstruct
	private void init() {
		initLazyDataModel();
		receiptProductInfos = receiptProductInfoService.findAllProductIdAndName();
	}

	public void onReset() {
		initLazyDataModel();
	}

	private void initLazyDataModel() {
		$ = new ReceiptOrderStatisticsRequest();
		lazyDataModel = new ReceiptOrderStatisticsLazyDataModel($);
	}


	@Override
	protected List<String> getDictionaryCodes() {
		return Lists.newArrayList(DictionaryCode.RECEIPT_ORDER_SOURCE_FROM);

	}

}
